package com.yanggu.mapreduce.combinesmallfile;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @version V1.0
 * @author: YangGu
 * @date: 2019/12/14 23:47
 * @description:
 */
public class CombineSmallFileMapper extends Mapper<LongWritable, Text, Text, IntWritable> {

    private Text k = new Text();

    private IntWritable v = new IntWritable(1);

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //1. 获取一行
        String line = value.toString();

        //2. 分割一行字符串(通过空格进行分割)
        String[] fields = line.split(" ");

        //3. 设置mapper的输出的key和value，写出
        for (String field : fields) {
            k.set(field);
            context.write(k, v);
        }
    }
}
